package kotan.view.auth;

import javax.swing.JDialog;

import kotan.AuthInfo;
import kotan.Kotan;

public class AuthDialog {
    
    public static AuthInfo showDialog(String email) {
        class AuthInfoHolder {
            volatile AuthInfo authInfo = AuthInfo.NO_AUTH;
        }
        final JDialog dialog = new JDialog(Kotan.get().getMainFrame());
        dialog.setModal(true);
        final AuthInfoHolder holder = new AuthInfoHolder();
        dialog.setTitle("Require login");
        @SuppressWarnings("serial")
        final AuthPanel panel = new AuthPanel() {

            @Override
            protected void onLogin() {
                super.onLogin();
                holder.authInfo = new AuthInfo(emailFeild.getText(), passwordField.getPassword());
                dialog.dispose();
            }

            @Override
            protected void onCancel() {
                super.onCancel();
                holder.authInfo = AuthInfo.NO_AUTH;
                dialog.dispose();
            }

        };
        panel.emailFeild.setText(email);
        dialog.add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(Kotan.get().getMainFrame());
        dialog.setVisible(true);
        return holder.authInfo;
    }

}
